Exemplo n.º 1
0
        private static void LoadFile(string path)
        {
            var info = new FileInfo(path);

            if (!info.Exists)
            {
                throw new FileNotFoundException();
            }

            path = info.Directory != null ? info.Directory.FullName : String.Empty;

            var io = path.IndexOf(_Path, StringComparison.OrdinalIgnoreCase);

            if (io > -1)
            {
                path = path.Substring(io + _Path.Length);
            }

            var parts = path.Split(Path.DirectorySeparatorChar);

            var scope = String.Join(".", parts.Where(p => !String.IsNullOrWhiteSpace(p)));

            if (scope.Length > 0)
            {
                scope += ".";
            }

            scope += Path.GetFileNameWithoutExtension(info.Name);

            var lines = File.ReadAllLines(info.FullName);

            var desc = new List <string>(0x10);

            for (int i = 0, idx = 0; i < lines.Length; i++)
            {
                var line = lines[i].Trim();

                if (String.IsNullOrWhiteSpace(line))
                {
                    desc.Clear();
                    continue;
                }

                if (line.StartsWith("#"))
                {
                    desc.Add(line.TrimStart('#').Trim());
                    continue;
                }

                var useDef = false;

                if (line.StartsWith("@"))
                {
                    useDef = true;
                    line   = line.TrimStart('@').Trim();
                }

                io = line.IndexOf('=');

                if (io < 0)
                {
                    throw new FormatException(String.Format("Bad format at line {0}", i + 1));
                }

                var key = line.Substring(0, io);
                var val = line.Substring(io + 1);

                if (String.IsNullOrWhiteSpace(key))
                {
                    throw new NullReferenceException(String.Format("Key can not be null at line {0}", i + 1));
                }

                key = key.Trim();

                if (String.IsNullOrEmpty(val))
                {
                    val = null;
                }

                var e = new Entry(info.FullName, idx++, scope, String.Join(String.Empty, desc), key, val, useDef);

                _Entries[String.Format("{0}.{1}", e.Scope, e.Key)] = e;

                desc.Clear();
            }
        }
Exemplo n.º 2
0
        public const int CheckTimeInHeartbeats = 6 * 10; //  every 10min

        private static void AddToIpTables(Entry entry, int rule)
        {
            Helper.WriteTextAsyncWrapper("ip_list", entry.Address + Environment.NewLine);
            CConsole.ColorWarning(() => Console.WriteLine("Added {0} to ip_list (rule #{1})", entry.Address, rule.ToString()));
            entries.TryRemove(entry.Address);
        }