Exemplo n.º 1
0
        public static bool TryParse(string map, out HostMap output)
        {
            output = null;
            var parts = map
                        .Split(' ', '\t')
                        .Where(x => !string.IsNullOrEmpty(x)).ToArray();

            if (parts.Length < 2)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(parts[1].Trim()))
            {
                return(false);
            }

            if (IPAddress.TryParse(parts[0], out var parseIP))
            {
                output = new HostMap(parseIP, parts[1]);
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        public static void RemoveAll()
        {
            List <string> hostOutput = new List <string>();

            foreach (var line in HostFileLines)
            {
                if (!HostMap.IsMap(line))
                {
                    hostOutput.Add(line);
                }
            }
            SaveHostFile(hostOutput);
        }
Exemplo n.º 3
0
        private static HostMap[] GetMaps()
        {
            var maps = new List <HostMap>();

            foreach (var line in HostFileLines)
            {
                if (HostMap.TryParse(line, out var map))
                {
                    maps.Add(map);
                }
            }
            return(maps.ToArray());
        }
Exemplo n.º 4
0
        public static void Add(HostMap myMap)
        {
            foreach (var line in HostFileLines)
            {
                if (HostMap.TryParse(line, out var map))
                {
                    if (map.Equals(myMap))
                    {
                        return;
                    }
                }
            }
            var hostFileLines = HostFileLines.Append(myMap.ToString());

            SaveHostFile(hostFileLines);
        }
Exemplo n.º 5
0
        public static void RemoveByHostName(string hostname)
        {
            var hostFileLines = HostFileLines.ToList();

            foreach (var line in hostFileLines)
            {
                if (HostMap.TryParse(line, out var map))
                {
                    if (map.HostName == hostname)
                    {
                        hostFileLines.Remove(line);
                        break;
                    }
                }
            }
            SaveHostFile(hostFileLines);
        }
Exemplo n.º 6
0
        public static void RemoveByIp(IPAddress ip)
        {
            var hostFileLines = HostFileLines.ToList();

            foreach (var line in hostFileLines)
            {
                if (HostMap.TryParse(line, out var map))
                {
                    if (map.Address.Equals(ip))
                    {
                        hostFileLines.Remove(line);
                        break;
                    }
                }
            }
            SaveHostFile(hostFileLines);
        }
Exemplo n.º 7
0
 protected bool Equals(HostMap other)
 {
     return(Equals(address, other.address) && string.Equals(hostName, other.hostName));
 }
Exemplo n.º 8
0
 public static void Add(string mapLine)
 {
     HostMap.TryParse(mapLine, out var map);
     Add(map);
 }