/// <summary>
        /// Init word
        /// </summary>
        public static void Init()
        {
            _filter = new BadWordsFilter();
            var cacheSet = new ShareCacheStruct <SensitiveWord>();

            cacheSet.Foreach((k, v) =>
            {
                _filter.AddKey(v.Word);
                return(true);
            });
        }
예제 #2
0
    /// <summary>
    /// Loads from file.
    /// </summary>
    private bool loadFromFile(string path)
    {
        ConsoleEx.DebugLog("Load Sensitive Filter data here..");
        bool success = false;

        StreamReader sr   = null;
        FileStream   fs   = File.OpenRead(path);
        string       line = null;

        try {
            sr = new StreamReader(fs);
            if (sr != null)
            {
                while (!string.IsNullOrEmpty(line = sr.ReadLine()))
                {
                    if (!line.StartsWith("#"))
                    {
                        string[] contain = line.Split('@'); // we define @ as split charactor
                        if (contain != null && contain.Length > 0)
                        {
                            foreach (string name in contain)
                            {
                                if (!string.IsNullOrEmpty(name))
                                {
                                    badWorldFilter.AddKey(name);
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception ex) {
            ConsoleEx.DebugLog(ex.ToString() + "\nError Line = " + line);
            success = false;
        } finally {
            if (sr != null)
            {
                sr.Close(); sr = null;
            }
            if (fs != null)
            {
                fs.Close(); fs = null;
            }

            #if DEBUG
            ConsoleEx.DebugLog(ConfigType.SensitiveData.ToString());
            #endif
        }
        return(success);
    }
예제 #3
0
 /// <summary>
 /// Init word
 /// </summary>
 public static void Init()
 {
     _filter = new BadWordsFilter(); 
     var cacheSet = new ShareCacheStruct<SensitiveWord>();
     cacheSet.Foreach((k, v) =>
     {
         _filter.AddKey(v.Word);
         return true;
     });
 }