/// <summary>
        ///
        /// </summary>
        /// <param name="doTryStoredCredentials">Call it first with this true, but if that doesn't work, call with this
        /// false so that we ask the user again</param>
        /// <returns></returns>
        public static ICredentials GetCredentials(bool doTryStoredCredentials)
        {
            ProxyCredentialSettings settings = new ProxyCredentialSettings();

            using (var dlg = new ProxyCredentialsRequestDialog())
            {
                string userName = string.Empty;
                string password = string.Empty;
                try
                {
                    string encryptedUserName;
                    string encryptedPassword;
                    ReadProxyCredentials(out encryptedUserName, out encryptedPassword);
                    userName = RobustNetworkOperation.GetClearText(encryptedUserName);
                    password = RobustNetworkOperation.GetClearText(encryptedPassword);
                }
                catch (Exception)
                {
                    //swallow and just give them blanks in the dialog
                }

                // should we ask the user for info?
                if (!doTryStoredCredentials || string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
                {
                    dlg._userName.Text = userName;
                    dlg._password.Text = password;
                    if (DialogResult.OK != dlg.ShowDialog(null))
                    {
                        return(null);
                    }
                    if (string.IsNullOrEmpty(dlg._userName.Text))
                    {
                        return(null);
                    }
                    if (string.IsNullOrEmpty(dlg._password.Text))
                    {
                        return(null);
                    }
                    if (dlg._remember.Checked)
                    {
                        SaveProxyCredentials(GetEncryptedText(userName), GetEncryptedText(password));
                    }
                }

                return(new NetworkCredential(userName, password));
            }
        }
 public void DoHttpGetAndGetProxyInfo()
 {
     string host, userName, password;
     bool   gotProxy = RobustNetworkOperation.DoHttpGetAndGetProxyInfo("http://hg.palaso.org/", out host, out userName, out password, s => Debug.WriteLine(s));
 }