Пример #1
0
        // 得到所有配置
        public static Dictionary <string, int> GetSettingsAll(User user)
        {
            String securityStr = user.Security;

            Dictionary <string, int> settings = getSettingValueByString(securityStr);

            Dictionary <string, int> dic = new Dictionary <string, int>();

            FieldInfo[] fields = typeof(UserPermission).GetFields();

            foreach (FieldInfo f in fields)
            {
                if (f.Name == "value__")
                {
                    continue;
                }

                int val = UserPrivacy.GetDefaultValue();
                if (settings.ContainsKey(f.Name))
                {
                    val = settings[f.Name];
                }
                dic.Add(f.Name, val);
            }

            return(dic);
        }
Пример #2
0
        public static String Save(Dictionary <String, int> settings)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("{");

            FieldInfo[] fields = typeof(UserPermission).GetFields();

            foreach (FieldInfo f in fields)
            {
                if (f.Name == "value__")
                {
                    continue;
                }

                int val = UserPrivacy.GetDefaultValue();
                if (settings.ContainsKey(f.Name))
                {
                    val = settings[f.Name];
                }

                sb.AppendFormat("{0}:{1},", f.Name, val);
            }


            sb.Append("}");

            return(sb.ToString());
        }
Пример #3
0
        // 查询
        private static int GetPrivacy(User user, UserPermission up)
        {
            int defaultValue = UserPrivacy.GetDefaultValue();

            String securityStr = user.Security;

            if (strUtil.IsNullOrEmpty(securityStr))
            {
                return(defaultValue);                                      //默认值
            }
            Dictionary <string, int> settings = getSettingValueByString(securityStr);

            int val = defaultValue;//默认值

            if (settings.ContainsKey(up.ToString()))
            {
                val = settings[up.ToString()];
            }

            return(val);
        }