示例#1
0
        public void AddEntry(HostEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            if (HostEntry.IsIgnoredHostname(entry.Name))
            {
                throw new ArgumentException("The following hostnames cannot be configured: " + String.Join(", ", HostEntry.IgnoredHostnames));
            }

            if (!entries.Contains(entry))
            {
                entries.Add(entry);
            }
        }
示例#2
0
        public void DeleteEntry(HostEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            if (entries.Contains(entry))
            {
                if (!(entry.IsNew || deletedLines.Contains(entry.Line)))
                {
                    deletedLines.Add(entry.Line);
                }

                entries.Remove(entry);
            }
        }
示例#3
0
        private void Load(Stream stream)
        {
            deletedLines = new List <int>();

            this.lines = ReadAllLines(stream);

            List <HostEntry> entriesList = new List <HostEntry>();

            for (int i = 0; i < lines.Length; i++)
            {
                HostEntry entry = ParseHostEntry(i, lines[i]);

                if (!(entry == null || HostEntry.IsIgnoredHostname(entry.Name)))
                {
                    entriesList.Add(entry);
                }
            }

            this.entries = entriesList;
        }