Exemplo n.º 1
0
        /// <summary>
        /// 本地敏感库,文件修改后,重新创建缓存Bit
        /// </summary>
        /// <returns></returns>
        public static IllegalWordsSearch GetIllegalWordsSearch()
        {
            if (!File.Exists(UrlsPath) || !File.Exists(KeywordsPath))
            {
                return(new IllegalWordsSearch());
            }

            if (_search == null)
            {
                string ipath = Path.GetFullPath(InfoPath);
                if (File.Exists(ipath) == false)
                {
                    _search = CreateIllegalWordsSearch();
                }
                else
                {
                    var texts = File.ReadAllText(ipath).Split('|');
                    if (new FileInfo(Path.GetFullPath(KeywordsPath)).LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") !=
                        texts[0] ||
                        new FileInfo(Path.GetFullPath(UrlsPath)).LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") !=
                        texts[1]
                        )
                    {
                        _search = CreateIllegalWordsSearch();
                    }
                    else
                    {
                        var s = new IllegalWordsSearch();
                        s.Load(Path.GetFullPath(BitPath));
                        _search = s;
                    }
                }
            }
            return(_search);
        }
Exemplo n.º 2
0
 private static IllegalWordsSearch GetIllegalWordsSearch()
 {
     if (_search == null)
     {
         var ipath = Path.GetFullPath(infoPath);
         if (File.Exists(ipath) == false)
         {
             _search = CreateIllegalWordsSearch();
         }
         else
         {
             var texts = File.ReadAllText(ipath).Split('|');
             if (new FileInfo(Path.GetFullPath(keywordsPath)).LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") !=
                 texts[0] ||
                 new FileInfo(Path.GetFullPath(urlsPath)).LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") !=
                 texts[1]
                 )
             {
                 _search = CreateIllegalWordsSearch();
             }
             else
             {
                 var s = new IllegalWordsSearch();
                 try {
                     s.Load(Path.GetFullPath(bitPath));
                 } catch (Exception ex) {
                     Console.WriteLine(ex.Message);
                     throw;
                 }
                 _search = s;
             }
         }
     }
     return(_search);
 }