Esempio n. 1
0
        /// <summary>
        /// 按照字符串内容加载内容,顺带清除重复冲突的内容
        /// </summary>
        /// <param name="formatString">字符串内容,通常由SaveAsFormattedString()得到的</param>
        public static BanInfo LoadFromJSON(string formatString)
        {
            BanInfo info = JsonConvert.DeserializeObject <BanInfo>(formatString);

            Action <Rule> gen_regex = r => r.regex = new Regex(r.RuleExpression);

            info.BanRules.ForEach(gen_regex);
            info.WhitelistRules.ForEach(gen_regex);

            var list = info.WhitelistRules.Concat(info.BanRules);

            info.rule_id_gerenator = list.Count() != 0?list.Max(r => r.RuleID):0;

            HashSet <int>    check      = new HashSet <int>();
            Predicate <Rule> check_func = p =>
            {
                if (check.Contains(p.RuleID))
                {
                    return(true);
                }
                check.Add(p.RuleID);
                return(false);
            };

            info.WhitelistRules.RemoveAll(check_func);
            info.BanRules.RemoveAll(check_func);

            HashSet <string>   check_str      = new HashSet <string>();
            Predicate <string> check_str_func = p =>
            {
                if (check_str.Contains(p))
                {
                    return(true);
                }
                check_str.Add(p);
                return(false);
            };

            info.WhitelistUsers.RemoveAll(check_str_func);
            check_str.Clear();
            info.BanUsers.RemoveAll(check_str_func);

            return(info);
        }
Esempio n. 2
0
        public static BanInfo LoadBanInfo(string save_path)
        {
            try
            {
                var content = File.ReadAllText(save_path);
                return(BanInfo.LoadFromJSON(content));
            }
            catch (Exception e)
            {
                Log.Error("Can't load baninfo save file,program will backup old and create default new.Please check your file if is vaild.:" + e.Message);

                if (File.Exists(save_path))
                {
                    File.Move(save_path, save_path + ".back");
                }

                var info    = new BanInfo();
                var content = info.SaveAsFormattedString();
                File.WriteAllText(save_path, content);

                return(info);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// 钦定过滤控制器,里面包含着黑名单白名单相关内容
 /// </summary>
 /// <param name="control">新的控制器</param>
 public void SetFliterControl(BanInfo control)
 {
     this.info = control;
 }