Ejemplo n.º 1
0
        /// <summary>
        /// 指定路径,创建Database的新实例
        /// </summary>
        /// <param name="basePath"></param>
        public Database(string basePath)
        {
            try
            {
                this.basePath = basePath;
                Directory.CreateDirectory(BindPath);
                Directory.CreateDirectory(NicknamePath);
                string bindData = "";
                try
                {
                    bindData = File.ReadAllText(BindFilename);
                }
                catch (FileNotFoundException)
                {
                    bindData = "";
                }
                BindData = DeserializeObject <Dictionary <long, BindingData> >(bindData) ?? new Dictionary <long, BindingData>();
                string cachedData = "";
                try
                {
                    cachedData = File.ReadAllText(CachedFilename);
                }
                catch (FileNotFoundException)
                {
                    cachedData = "";
                }
                CachedData = DeserializeObject <Dictionary <long, CachedData> >(cachedData) ?? new Dictionary <long, CachedData>();
                string nickData = string.Empty;
                try
                {
                    nickData = File.ReadAllText(NicknameFilename);
                }
                catch (FileNotFoundException)
                {
                    nickData = string.Empty;
                }
                NicknameData   = DeserializeObject <Dictionary <string, long> >(nickData) ?? new Dictionary <string, long>();
                Administrators = new DataHolder <ISet <long> >(AdministratorsPath, new HashSet <long>());
                Tips           = new DictionaryHolder <string, string>(TipsPath,
                                                                       new Dictionary <string, string>(StatelessFunctions.ManageTips.DefaultTips
                                                                                                       .Select(tip => new KeyValuePair <string, string>(tip.ToLowerInvariant(), tip))));

                if (single == null)
                {
                    single = this;
                }
            }
            catch (Exception e)
            {
                Logger.LogException(e);
                throw;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 指定路径,创建Database的新实例
 /// </summary>
 /// <param name="basePath"></param>
 public Database(string basePath)
 {
     try
     {
         this.basePath = basePath;
         Directory.CreateDirectory(BindPath);
         Directory.CreateDirectory(NicknamePath);
         string bindData = "";
         try
         {
             bindData = File.ReadAllText(BindFilename);
         }
         catch (FileNotFoundException)
         {
             bindData = "";
         }
         BindData = DeserializeObject <Dictionary <long, BindingData> >(bindData) ?? new Dictionary <long, BindingData>();
         string cachedData = "";
         try
         {
             cachedData = File.ReadAllText(CachedFilename);
         }
         catch (FileNotFoundException)
         {
             cachedData = "";
         }
         CachedData = DeserializeObject <Dictionary <long, CachedData> >(cachedData) ?? new Dictionary <long, CachedData>();
         string nickData = string.Empty;
         try
         {
             nickData = File.ReadAllText(NicknameFilename);
         }
         catch (FileNotFoundException)
         {
             nickData = string.Empty;
         }
         NicknameData   = DeserializeObject <Dictionary <string, long> >(nickData) ?? new Dictionary <string, long>();
         Administrators = new DataHolder <ISet <long> >(AdministratorsPath, new HashSet <long>());
         if (single == null)
         {
             single = this;
         }
     }
     catch (Exception e)
     {
         Logger.LogException(e);
         throw;
     }
 }