static CFProxy[] ParseProxies(IntPtr proxyList) { CFProxy[] proxies = null; if (proxyList != IntPtr.Zero) { // it was retained in the cbs. using (var array = new CFArray(proxyList, false)) { proxies = new CFProxy [array.Count]; for (int i = 0; i < proxies.Length; i++) { var dict = Runtime.GetNSObject <NSDictionary> (array.GetValue(i)); proxies[i] = new CFProxy(dict); } } } return(proxies); }
static Uri GetProxyUri(CFProxy proxy, out NetworkCredential credentials) { string protocol; switch (proxy.ProxyType) { case CFProxyType.FTP: protocol = "ftp://"; break; case CFProxyType.HTTP: case CFProxyType.HTTPS: protocol = "http://"; break; default: credentials = null; return(null); } string username = proxy.Username; string password = proxy.Password; string hostname = proxy.HostName; int port = proxy.Port; string uri; if (username != null) { credentials = new NetworkCredential(username, password); } else { credentials = null; } uri = protocol + hostname + (port != 0 ? ':' + port.ToString() : string.Empty); return(new Uri(uri, UriKind.Absolute)); }