/// <summary>Initializes a new instance of the <see cref="ConnectionSettings"/> class.</summary> /// <param name="address">The proxy address to use for all protocols.</param> public ConnectionSettings(ProxyAddress address) : this(address, address, address, address) { }
// Methods /// <summary>Gets the current configuration.</summary> /// <returns> /// A <see cref="ConnectionSettings" /> instance representing the current network configuration. /// </returns> public static ConnectionSettings GetCurrentConfig() { var sep = new[] { ';' }; var rmvEmpty = StringSplitOptions.RemoveEmptyEntries; var nc = new ConnectionSettings(); var reg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(keyName); // connection type checkboxes var checks = reg.OpenSubKey("Connections") .GetValue("DefaultConnectionSettings", new byte[10]) .As <byte[]>()[8]; foreach (var flag in ((ConnectionType)checks).GetAllFlagsPresent()) { nc.ConnectionType |= flag; } // // This check may not be needed since the value is likely to be set from // DefaultConnectionSettings. It is however kept here as a fail-safe measure // since Microsoft decided to set the value at two different locations. // if (reg.GetValue("ProxyEnable", 0).As <int>() == 1) { nc.ConnectionType |= ConnectionType.ManualProxy; } // autoconfig url nc.AutoConfigUrl = (string)reg.GetValue("AutoConfigUrl", ""); // proxy overrides var overrides = reg.GetValue("ProxyOverride", "").As <string>().Split(sep, rmvEmpty); // proxy servers; initialize them all to default ProxyAddress http = ProxyAddress.Default, https = http, ftp = http, socks = http; var proxies = reg.GetValue("ProxyServer", "").As <string>().ToLower().Split(sep, rmvEmpty); if (proxies.Length == 1 && !proxies[0].Contains("=")) // single HTTP proxy won't have an equal sign { http = new ProxyAddress(proxies[0]); } else { foreach (var proxy in proxies) { var p = proxy.Split(new[] { '=' }, rmvEmpty); if (p[0] == "http") { http = new ProxyAddress(p[1]); } else if (p[0] == "https") { https = new ProxyAddress(p[1]); } else if (p[0] == "ftp") { ftp = new ProxyAddress(p[1]); } else if (p[0] == "socks") { socks = new ProxyAddress(p[1]); } } } nc._proxies = new ProxySettings(http, https, ftp, socks, overrides); return(nc); }
/// <summary>Initializes a new instance of the <see cref="ProxySettings" /> class.</summary> /// <param name="proxyAddress">The proxy address to use for all protocols.</param> /// <param name="exceptions">The host addresses that do not require a proxy server.</param> public ProxySettings(ProxyAddress proxyAddress, params string[] exceptions) : this(proxyAddress, null, null, null, exceptions) { }
/// <summary>Initializes a new instance of the <see cref="ProxySettings"/> class.</summary> /// <param name="httpProxy">The proxy address to use for the HTTP protocol.</param> /// <param name="httpsProxy">The proxy address to use for the HTTPS protocol.</param> /// <param name="ftpProxy">The proxy address to use for the FTP protocol.</param> /// <param name="socksProxy">The proxy address to use for the SOCKS protocol.</param> public ProxySettings(ProxyAddress httpProxy, ProxyAddress httpsProxy, ProxyAddress ftpProxy, ProxyAddress socksProxy) : this(httpProxy, httpsProxy, ftpProxy, socksProxy, Local) { }
/// <summary>Initializes a new instance of the <see cref="ProxySettings"/> class.</summary> /// <param name="proxyAddress">The proxy address to use for all protocols.</param> public ProxySettings(ProxyAddress proxyAddress) : this(proxyAddress, Local) { }