예제 #1
0
 public void Remove(HostEntry host)
 {
     _hostEntries.Remove(host);
 }
예제 #2
0
 public void Add(HostEntry host)
 {
     _hostEntries.Add(host);
 }
        public void ToggleStatus(HostEntry host)
        {
            PendingChanges = true;

            if (host.Enabled)
            {
                Status = "Host Enabled";
            }
            else
            {
                Status = "Host Disabled";
            }
        }
예제 #4
0
        /// <summary>
        /// Parses a line from the host file into an HostEntry object.
        /// </summary>
        /// <param name="hostEntryLine">The line from the hosts file to parse.</param>
        /// <returns>The HostEntry object.</returns>
        public static HostEntry Parse(string hostEntryLine)
        {
            var hostEntry = new HostEntry(hostEntryLine)
            {
                IsValid = false,
            };

            if (hostEntryLine.StartsWith("# ") || hostEntryLine.Length <= 1 || hostEntryLine.StartsWith("#\t"))
            {
                // skip the Microsoft banner text
            }
            else
            {
                var split = hostEntryLine.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

                if (split[0].StartsWith("#"))
                {
                    split[0] = split[0].Replace("#", "");
                    hostEntry.Enabled = false;
                }
                else
                {
                    hostEntry.Enabled = true;
                }

                IPAddress ipAddress;
                if (IPAddress.TryParse(split[0], out ipAddress))
                {
                    hostEntry.Address = ipAddress.ToString();
                    hostEntry.Hostname = split[1];
                    hostEntry.IsValid = true;
                }
            }

            return hostEntry;
        }
 public void RemoveHost(HostEntry host)
 {
     _hostsFile.Remove(host);
     Hosts.Remove(host);
     PendingChanges = true;
     Status = "Host Removed";
 }