Exemple #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);
        }
Exemple #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);
        }
Exemple #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());
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #7
0
 protected bool Equals(HostMap other)
 {
     return(Equals(address, other.address) && string.Equals(hostName, other.hostName));
 }
Exemple #8
0
 public static void Add(string mapLine)
 {
     HostMap.TryParse(mapLine, out var map);
     Add(map);
 }