예제 #1
0
파일: Static.cs 프로젝트: qinzhixian/Part
 /// <summary>
 /// 保存数据
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="type"></param>
 /// <param name="list"></param>
 private static void SaveChanges <T>(List <T> list)
 {
     StaticDao.SaveChanges(list, GlobalData, DataFilePath);
     //ThreadPool.QueueUserWorkItem((s) =>
     //{
     //    StaticDao.SaveChanges(list, GlobalData, DataFilePath);
     //    Thread.Sleep(1000 * 2);
     //});
 }
예제 #2
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="dataAssemblyName"></param>
        public static void Start(string dataAssemblyName)
        {
            if (!string.IsNullOrEmpty(dataAssemblyName))
            {
                DataAssemblyName = dataAssemblyName;
            }

            var typeList = Util.Reflection.AssemblyUtil.GetTypeListOfImplementedInterface(DataAssemblyName, typeof(Interface.IDbModel)).ToArray();

            if (GlobalData == null)
            {
                GlobalData = new Dictionary <Type, List <object> >();
            }

            GlobalData = StaticDao.ReadData(GlobalData, typeList);
        }
예제 #3
0
 /// <summary>
 /// 添加数据
 /// </summary>
 /// <param name="dataAry"></param>
 public static void Add <T>(params T[] dataAry)
 {
     lock (locker)
     {
         var list = GetList <T>();
         list.AddRange(dataAry);
         SaveChanges(list);
     }
     foreach (var item in dataAry)
     {
         Excute(() =>
         {
             StaticDao.Add(item);
         });
     }
 }
예제 #4
0
파일: Static.cs 프로젝트: qinzhixian/Part
        /// <summary>
        /// 读取数据
        /// </summary>
        /// <param name="typeList"></param>
        private static void ReadData(params Type[] typeList)
        {
            foreach (var type in typeList)
            {
                if (!DataFilePath.ContainsKey(type))
                {
                    DataFilePath.Add(type, StaticDao.GetDataFilePath(type, DataDirPath));
                }

                if (!GlobalData.ContainsKey(type))
                {
                    var data = StaticDao.ReadGlobalData(type, DataFilePath[type]);
                    GlobalData.Add(type, data);
                }
            }
        }
예제 #5
0
 /// <summary>
 /// 删除数据
 /// </summary>
 /// <param name="dataAry"></param>
 public static void Remove <T>(params T[] dataAry)
 {
     lock (locker)
     {
         var list = GetList <T>();
         foreach (var item in dataAry)
         {
             list.Remove(item);
         }
         SaveChanges(list);
     }
     foreach (var item in dataAry)
     {
         Excute(() =>
         {
             StaticDao.Del(item);
         });
     }
 }
예제 #6
0
 /// <summary>
 /// 删除数据
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="where"></param>
 public static void Remove <T>(Func <T, bool> where)
 {
     T[] entityList = new T[] { };
     lock (locker)
     {
         var list = GetList <T>();
         entityList = list.Where(where).ToArray();
         foreach (var item in entityList)
         {
             list.Remove(item);
         }
         SaveChanges(list);
     }
     foreach (var item in entityList)
     {
         Excute(() =>
         {
             StaticDao.Del(item);
         });
     }
 }
예제 #7
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="oldEntity"></param>
        /// <param name="newEntity"></param>
        public static void Update <T>(Func <T, bool> where, T newEntity)
        {
            T[] oldEntityList = new T[] { };
            lock (locker)
            {
                var list = GetList <T>();
                oldEntityList = list.Where(where).ToArray();
                foreach (var item in oldEntityList)
                {
                    list.Remove(item);
                    list.Add(newEntity);
                }

                SaveChanges(list);
            }
            foreach (var item in oldEntityList)
            {
                Excute(() =>
                {
                    StaticDao.Update(item, newEntity);
                });
            }
        }