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); }
public static void RemoveAll() { List <string> hostOutput = new List <string>(); foreach (var line in HostFileLines) { if (!HostMap.IsMap(line)) { hostOutput.Add(line); } } SaveHostFile(hostOutput); }
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()); }
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); }
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); }
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); }
protected bool Equals(HostMap other) { return(Equals(address, other.address) && string.Equals(hostName, other.hostName)); }
public static void Add(string mapLine) { HostMap.TryParse(mapLine, out var map); Add(map); }