示例#1
0
 public void NetworkCredentialFactory_ValidateOrEmpty_Tests()
 {
     Assert.IsTrue(NetworkCredentialFactory.ValidateOrEmpty("Username", "Password", out _));
     Assert.IsFalse(NetworkCredentialFactory.ValidateOrEmpty("Username", String.Empty, out _));
     Assert.IsFalse(NetworkCredentialFactory.ValidateOrEmpty(String.Empty, "Password", out _));
     Assert.IsTrue(NetworkCredentialFactory.ValidateOrEmpty(String.Empty, String.Empty, out _));
 }
示例#2
0
        /// <summary>
        /// Creates a WebProxy object based on preference settings.
        /// </summary>
        public static WebProxy Create(IPreferences preferences)
        {
            if (preferences == null || !preferences.Get <bool>(Preference.UseProxy))
            {
                return(null);
            }

            var proxy = new WebProxy(
                preferences.Get <string>(Preference.ProxyServer),
                preferences.Get <int>(Preference.ProxyPort));

            if (preferences.Get <bool>(Preference.UseProxyAuth))
            {
                proxy.Credentials = NetworkCredentialFactory.Create(
                    preferences.Get <string>(Preference.ProxyUser),
                    preferences.Get <string>(Preference.ProxyPass));
            }
            return(proxy);
        }