Пример #1
0
 public static IPManager GetInstance()
 {
     if (INSTANCE == null)
     {
         INSTANCE = new IPManager();
     }
     return(INSTANCE);
 }
Пример #2
0
        private static void ReadFile(List <FileInfo> files, string sourceFile, FileSettingElement settings)
        {
            settings.SourceFile = sourceFile;
            string searchType = settings.DoSearch;
            bool   search     = !searchType.Equals("off");

            string[] searchTerms = (!search ? null : settings.SearchPattern.Split(new string[] { "\\n" }, StringSplitOptions.None));
            foreach (FileInfo file in files)
            {
                foreach (string line in File.ReadLines(file.FullName))
                {
                    bool matches = true;
                    if (line.StartsWith(settings.CommentStart) && settings.CommentStart != "")
                    {
                        continue;
                    }

                    if (search)
                    {
                        switch (searchType)
                        {
                        case "none":
                            foreach (var term in searchTerms)
                            {
                                if (line.Contains(term))
                                {
                                    matches = false;
                                    break;
                                }
                            }
                            break;

                        case "any":
                            matches = false;
                            foreach (var term in searchTerms)
                            {
                                if (line.Contains(term))
                                {
                                    matches = true;
                                    break;
                                }
                            }
                            break;

                        case "all":
                            foreach (var term in searchTerms)
                            {
                                if (!line.Contains(term))
                                {
                                    matches = false;
                                    break;
                                }
                            }
                            break;

                        default:
                            Logger.GetINSTANCE().LogError("invalid value of doSearch parameter in config, use 'off'/'none'/'any'/'all'");
                            break;
                        }
                    }
                    if (!matches)
                    {
                        continue;
                    }

                    try
                    {
                        string ip = line.Split(settings.Delim)[settings.IpIndex];
                        if (ip.Contains(':'))
                        {
                            ip = ip.Split(':')[0];
                        }
                        IPManager.GetInstance().Registrer(ip, settings);
                    }
                    catch (IndexOutOfRangeException)
                    {
                        throw new IndexOutOfRangeException("Line was not split as expected, have you forgotten to specify the commentPattern");
                    }
                }
            }
        }