Exemple #1
0
        private bool UpdateHosts(IIntegrationResult result, string host, string ip)
        {
            using (var fs = GetFileStream(result))
            {
                if (fs == null)
                {
                    return(false);
                }
                HostsCollection hosts;
                using (var sr = new StreamReader(fs, Encoding.UTF8))
                {
                    var text = sr.ReadToEnd();
                    hosts = new HostsCollection(text);

                    if (hosts[host] == ip)
                    {
                        return(true);
                    }
                    else
                    {
                        hosts[host] = ip;

                        string hostsContent = hosts.ToString();
                        var    contentBytes = Encoding.UTF8.GetBytes(hostsContent);
                        fs.Seek(0, SeekOrigin.Begin);
                        fs.SetLength(contentBytes.Length);
                        fs.Write(contentBytes, 0, contentBytes.Length);
                    }
                }
            }
            return(true);
        }