public void can_remove_entry_and_return_success_or_not() { var hostFile = new HostsFile(); hostFile.Set("127.0.0.1", "test.com"); Assert.False(hostFile.Remove("test1.com")); Assert.False(hostFile.Remove("127.0.0.1")); Assert.True(hostFile.Remove("test.com")); Assert.Equal(0, hostFile.Lines.Count); }
public void will_update_IsDirty_property_if_and_only_if_real_changes_are_made() { var hostFile = new HostsFile(); hostFile.Set("127.0.0.1", "test.com"); hostFile.MarkClean(); hostFile.Remove("test1.com"); Assert.False(hostFile.IsDirty); hostFile.Remove("test.com"); Assert.True(hostFile.IsDirty); }
public static string removeHostsItem(string domain) { try { HostsFile.Remove(domain); return("OK"); } catch (Exception e) { return(e.Message); } }
public void Duplicates(Filter filter, FilterProp what) { List <HostsFileLine> hosts; using (new Watch("read file")) { hosts = _hostsFile.GetHosts().ToList(); } var filterd = Filter(hosts, filter, what); var duplicates = (from f in filterd group f by $"{f.Ip.Value} {f.Domain.Value}" into g where g.Count() > 1 select g).ToList(); ConsoleEx.PrintWithPaging( list: duplicates, countAll: hosts.Count, line: (models, i) => new ConsoleWriter() .FormatLine("{count,5} {domain}", parms => parms .Add("count", models.Count()) .Add("domain", models.Key) ) .FormatLines(" {ip} {domain}", models.ToList(), (model, parms) => parms .Add("ip", model.Ip) .Add("domain", model.Domain) ) ); if (duplicates.Any()) { var toremove = duplicates.SelectMany(x => x.Skip(1).Select(_ => _.Model)).ToList(); if (ConsoleEx.AskForYes($"remove {toremove.Count} duplicates?")) { _hostsFile.Remove(toremove); toremove.ForEach(x => Console.WriteLine($"removed: {HostsFile.CreateTextLine(x)}")); } } }
// Try to remove specified domain from Windows Hosts file private bool RemoveEntry(string domainName) { try { HostsFile.Remove(domainName); return(true); } catch (SystemException) { return(false); } }
public void Dispose() { HostsFile.Remove(_hostname); ServicePointManager.DnsRefreshTimeout = _dnsRefreshTimeout; ServicePointManager.FindServicePoint(new Uri("http://testdns:9200")).ConnectionLeaseTimeout = _connectionLeaseTimeout; }
protected override void EndProcessing() { HostsFile.Remove(HostName); }