示例#1
0
        /// <summary>
        /// 保存指定字典对应的默认设置。如果与默认的设置相同则不保存
        /// </summary>
        /// <param name="wordbookName"></param>
        /// <param name="matchType"></param>
        /// <param name="isDynamic"></param>
        internal static void WriteSetting(string wordbookName, ShowListMatchType matchType, bool isDynamic)
        {
            if (String.IsNullOrEmpty(CurrentUserId) || String.IsNullOrEmpty(wordbookName))
            {
                return;
            }

            if ((matchType == DefaultMatchSetting.MatchType) && (isDynamic == DefaultMatchSetting.IsDynamic))
            {
                RemoveSetting(wordbookName);
            }
            else
            {
                // 缓存中不存在,则添加缓存,插入到注册表
                if (!CurrentUserSetting.ContainsKey(wordbookName))
                {
                    CurrentUserSetting.Add(wordbookName, new ShowListMatchTypeSetting(matchType, isDynamic));
                    WriteSettingToReg(wordbookName, CurrentUserSetting[wordbookName]);
                }
                // 检查与缓存中的数据是否一致,不一致时修改缓存,再更新注册表
                else
                {
                    if ((CurrentUserSetting[wordbookName].IsDynamic != isDynamic) ||
                        (CurrentUserSetting[wordbookName].MatchType != matchType))
                    {
                        CurrentUserSetting[wordbookName].IsDynamic = isDynamic;
                        CurrentUserSetting[wordbookName].MatchType = matchType;
                        WriteSettingToReg(wordbookName, CurrentUserSetting[wordbookName]);
                    }
                }
            }
        }
示例#2
0
 /// <summary>
 /// 读取指定字典对应的默认设置
 /// </summary>
 /// <param name="wordbookName"></param>
 /// <returns></returns>
 internal static ShowListMatchTypeSetting ReadDefaultSetting(string wordbookName)
 {
     if (String.IsNullOrEmpty(CurrentUserId) || String.IsNullOrEmpty(wordbookName))
     {
         return(DefaultMatchSetting);
     }
     // 首先检查缓存,如果没有则使用默认值(每个用户的设置是一次读入的)
     if (CurrentUserSetting.ContainsKey(wordbookName))
     {
         return(CurrentUserSetting[wordbookName]);
     }
     else
     {
         return(DefaultMatchSetting);
     }
 }
示例#3
0
 private static void RemoveSetting(string wordbookName)
 {
     if (!CurrentUserSetting.ContainsKey(wordbookName))
     {
         RegistryKey regKey = Registry.LocalMachine.OpenSubKey(CurrentUserRegFullKey, true);
         if (regKey == null)
         {
             return;
         }
         try {
             regKey.DeleteValue(wordbookName);
         }
         catch { }
         finally {
             regKey.Close();
         }
     }
 }