public void StartTimer(TimeSpan interval, Func <bool> callback) { NSTimer timer = null; #if __UNIFIED__ timer = NSTimer.CreateRepeatingScheduledTimer(interval, t => { #else timer = NSTimer.CreateRepeatingScheduledTimer(interval, () => { #endif if (!callback()) #if __UNIFIED__ { t.Invalidate(); } #else { timer.Invalidate(); } #endif }); NSRunLoop.Main.AddTimer(timer, NSRunLoopMode.Common); } HttpClient GetHttpClient() { var proxy = CFNetwork.GetSystemProxySettings(); var handler = new HttpClientHandler(); if (!string.IsNullOrEmpty(proxy.HTTPProxy)) { handler.Proxy = CFNetwork.GetDefaultProxy(); handler.UseProxy = true; } return(new HttpClient(handler)); }
public WebProxy GetProxySettings() { var systemProxySettings = CFNetwork.GetSystemProxySettings(); var proxyPort = systemProxySettings.HTTPPort; var proxyHost = systemProxySettings.HTTPProxy; return(!string.IsNullOrEmpty(proxyHost) && proxyPort != 0 ? new WebProxy($"{proxyHost}:{proxyPort}") : null); }
HttpClient GetHttpClient() { var proxy = CFNetwork.GetSystemProxySettings(); var handler = new HttpClientHandler(); if (!string.IsNullOrEmpty(proxy.HTTPProxy)) { handler.Proxy = CFNetwork.GetDefaultProxy(); handler.UseProxy = true; } return(new HttpClient(handler)); }
public WebProxy GetWebProxy() { CFProxySettings systemProxySettings = CFNetwork.GetSystemProxySettings(); string proxyHost = systemProxySettings.HTTPProxy; int proxyPort = systemProxySettings.HTTPPort; if (!string.IsNullOrWhiteSpace(proxyHost) && proxyPort != 0) { return(new WebProxy(proxyHost, proxyPort)); } return(null); }
public void WebProxy_Leak() { // note: needs to be executed under Instrument to verify it does not leak Assert.NotNull(CFNetwork.GetSystemProxySettings(), "should not leak"); }
public Uri GetProxy(Uri targetUri) { NetworkCredential credentials = null; Uri proxy = null; if (targetUri == null) { throw new ArgumentNullException("targetUri"); } try { CFProxySettings settings = CFNetwork.GetSystemProxySettings(); CFProxy[] proxies = CFNetwork.GetProxiesForUri(targetUri, settings); if (proxies != null) { for (int i = 0; i < proxies.Length && proxy == null; i++) { switch (proxies[i].ProxyType) { case CFProxyType.AutoConfigurationJavaScript: proxy = GetProxyUriFromScript(proxies[i].AutoConfigurationJavaScript, targetUri, out credentials); break; case CFProxyType.AutoConfigurationUrl: proxy = ExecuteProxyAutoConfigurationURL(proxies[i].AutoConfigurationUrl, targetUri, out credentials); break; case CFProxyType.HTTPS: case CFProxyType.HTTP: case CFProxyType.FTP: // create a Uri based on the hostname/port/etc info proxy = GetProxyUri(proxies[i], out credentials); break; case CFProxyType.SOCKS: // unsupported proxy type, try the next one break; case CFProxyType.None: // no proxy should be used proxy = targetUri; break; } } if (proxy == null) { // no supported proxies for this Uri, fall back to trying to connect to targetUri directly proxy = targetUri; } } else { proxy = targetUri; } } catch { // ignore errors while retrieving proxy data proxy = targetUri; } if (!userSpecified) { this.credentials = credentials; } return(proxy); }