Exemplo n.º 1
0
            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));
            }
Exemplo n.º 2
0
        public void WebProxy()
        {
            IWebProxy proxy = CFNetwork.GetDefaultProxy();

            Assert.True(proxy.IsBypassed(uri), "IsBypassed");
            Assert.That(proxy.GetProxy(uri), Is.SameAs(uri), "GetProxy");
        }
Exemplo n.º 3
0
 public IOSRequestBuilder()
 {
     //NOTE: DO NOT USE YOUR MASTER CREDENTIALS HERE
     BuildApplicationCredentials = () => new NetworkCredential("ApplicationName", "ApplicationSecret");
     ConfigureRequest = request =>
         {
             request.Proxy = CFNetwork.GetDefaultProxy();
             //only a suggested timeout
             request.Timeout = 30000;
         };
 }
Exemplo n.º 4
0
            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));
            }
Exemplo n.º 5
0
        public static IWebProxy GetSystemWebProxy()
        {
#if MONOTOUCH
            return(CFNetwork.GetDefaultProxy());
#else
#if MONODROID
            // Return the system web proxy.  This only works for ICS+.
            var androidProxy = AndroidPlatform.GetDefaultProxy();
            if (androidProxy != null)
            {
                return(androidProxy);
            }
#endif
#if !NET_2_1 && !SSHARP
            if (IsWindows())
            {
                int iProxyEnable =
                    (int)Microsoft.Win32.Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", "ProxyEnable", 0);

                if (iProxyEnable > 0)
                {
                    string    strHttpProxy   = "";
                    bool      bBypassOnLocal = false;
                    ArrayList al             = new ArrayList();

                    string strProxyServer =
                        (string)Microsoft.Win32.Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", "ProxyServer", null);
                    string strProxyOverrride =
                        (string)Microsoft.Win32.Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", "ProxyOverride", null);

                    if (strProxyServer.Contains("="))
                    {
                        foreach (string strEntry in strProxyServer.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            if (strEntry.StartsWith("http="))
                            {
                                strHttpProxy = strEntry.Substring(5);
                                break;
                            }
                        }
                    }
                    else
                    {
                        strHttpProxy = strProxyServer;
                    }

                    if (strProxyOverrride != null)
                    {
                        string[] bypassList = strProxyOverrride.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                        foreach (string str in bypassList)
                        {
                            if (str != "<local>")
                            {
                                al.Add(str);
                            }
                            else
                            {
                                bBypassOnLocal = true;
                            }
                        }
                    }

                    return(new WebProxy(strHttpProxy, bBypassOnLocal, al.ToArray(typeof(string)) as string[]));
                }
            }
            else
            {
#endif
#if !NETCF
            if (Platform.IsMacOS)
            {
                return(CFNetwork.GetDefaultProxy());
            }
#endif
#if !SSHARP
            string address = Environment.GetEnvironmentVariable("http_proxy");

            if (address == null)
            {
                address = Environment.GetEnvironmentVariable("HTTP_PROXY");
            }

            if (address != null)
            {
                try
                {
                    if (!address.StartsWith("http://"))
                    {
                        address = "http://" + address;
                    }

                    Uri       uri = new Uri(address);
                    IPAddress ip;

                    if (IPAddress.TryParse(uri.Host, out ip))
                    {
                        if (IPAddress.Any.Equals(ip))
                        {
                            UriBuilder builder = new UriBuilder(uri);
                            builder.Host = "127.0.0.1";
                            uri          = builder.Uri;
                        }
                        else if (IPAddress.IPv6Any.Equals(ip))
                        {
                            UriBuilder builder = new UriBuilder(uri);
                            builder.Host = "[::1]";
                            uri          = builder.Uri;
                        }
                    }

                    bool      bBypassOnLocal = false;
                    ArrayList al             = new ArrayList();
                    string    bypass         = Environment.GetEnvironmentVariable("no_proxy");

                    if (bypass == null)
                    {
                        bypass = Environment.GetEnvironmentVariable("NO_PROXY");
                    }

                    if (bypass != null)
                    {
                        string[] bypassList = bypass.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                        foreach (string str in bypassList)
                        {
                            if (str != "*.local")
                            {
                                al.Add(str);
                            }
                            else
                            {
                                bBypassOnLocal = true;
                            }
                        }
                    }

                    return(new WebProxy(uri, bBypassOnLocal, al.ToArray(typeof(string)) as string[]));
                }
                catch (UriFormatException)
                {
                }
            }
#if !NET_2_1
        }
#endif
#endif
            return(new WebProxy());
#endif // MONOTOUCH
        }