예제 #1
0
 protected void onInserted(valueType value)
 {
     if (!tree.TryAdd(getSort(value), value))
     {
         cache.SqlTable.Log.Fatal(typeof(valueType).FullName + " 缓存同步错误", LogLevel.Fatal | LogLevel.AutoCSer);
     }
 }
        /// <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)
        {
            int index = getIndex(value), oldIndex = getIndex(oldValue);

            if (index == oldIndex)
            {
                sortType sortKey = getSort(value), oldSortKey = getSort(oldValue);
                if (!sortKey.Equals(oldSortKey))
                {
                    AutoCSer.SearchTree.Dictionary <sortType, valueType> tree = treeArray[index];
                    if (tree != null)
                    {
                        bool isRemove = tree.Remove(oldSortKey), isAdd = tree.TryAdd(sortKey, cacheValue);
                        if (isRemove && isAdd)
                        {
                            return;
                        }
                    }
                    cache.SqlTable.Log.Fatal(typeof(valueType).FullName + " 缓存同步错误", LogLevel.Fatal | LogLevel.AutoCSer);
                }
            }
            else
            {
                onInserted(cacheValue, index);
                onDeleted(oldValue, oldIndex);
            }
        }
예제 #3
0
 protected void onInserted(valueType value)
 {
     if (!tree.TryAdd(getSort(value), value))
     {
         cache.SqlTable.Log.add(AutoCSer.Log.LogType.Fatal, typeof(valueType).FullName + " 缓存同步错误");
     }
 }
예제 #4
0
 /// <summary>
 /// 创建字典测试
 /// </summary>
 private static void createDictionary()
 {
     try
     {
         removeCount = 0;
         AutoCSer.Random random   = AutoCSer.Random.Default;
         int             keyIndex = keyCount;
         time.Restart();
         for (int nextCount = count; nextCount > keyIndex; --nextCount)
         {
             int index = (int)((uint)random.Next() & (keyCount - 1)), key = keys[index];
             if (index < keyIndex)
             {
                 if (!dictionary.TryAdd(ref key, key))
                 {
                     isError = true;
                     Console.WriteLine("ERROR");
                     return;
                 }
                 if (dictionary.Count != keyCount - keyIndex + 1)
                 {
                     isError = true;
                     Console.WriteLine("ERROR");
                     return;
                 }
                 keys[index]    = keys[--keyIndex];
                 keys[keyIndex] = key;
             }
             else
             {
                 if (!dictionary.Remove(ref key))
                 {
                     isError = true;
                     Console.WriteLine("ERROR");
                     return;
                 }
                 if (dictionary.Count != keyCount - keyIndex - 1)
                 {
                     isError = true;
                     Console.WriteLine("ERROR");
                     return;
                 }
                 keys[index] = keys[keyIndex];
                 ++removeCount;
                 keys[keyIndex++] = key;
             }
         }
         while (keyIndex != 0)
         {
             int index = (int)((uint)random.Next() % keyIndex), key = keys[index];
             if (!dictionary.TryAdd(ref key, key))
             {
                 isError = true;
                 Console.WriteLine("ERROR");
                 return;
             }
             if (dictionary.Count != keyCount - keyIndex + 1)
             {
                 isError = true;
                 Console.WriteLine("ERROR");
                 return;
             }
             keys[index]    = keys[--keyIndex];
             keys[keyIndex] = key;
         }
         time.Stop();
         if (dictionary.Count != keyCount)
         {
             isError = true;
             Console.WriteLine("ERROR");
             return;
         }
         for (int index = keyCount; index != 0;)
         {
             --index;
             if (dictionary.At(index).Key != index)
             {
                 isError = true;
                 Console.WriteLine("ERROR");
                 return;
             }
         }
     }
     finally
     {
         wait.Set();
     }
 }